package com.tms.goodsmanagement.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.tms.goodsmanagement.domain.Goodsmanagement;
import com.tms.goodsmanagement.service.IGoodsmanagementService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 货物管理Controller
 *
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/goodsmanagement")
public class GoodsmanagementController extends BaseController
{
    @Autowired
    private IGoodsmanagementService goodsmanagementService;

    /**
     * 查询货物管理列表
     */
    @RequiresPermissions("goodsmanagement:goodsmanagement:list")
    @GetMapping("/list")
    public TableDataInfo list(Goodsmanagement goodsmanagement)
    {
        startPage();
        List<Goodsmanagement> list = goodsmanagementService.selectGoodsmanagementList(goodsmanagement);
        return getDataTable(list);
    }

    /**
     * 导出货物管理列表
     */
    @RequiresPermissions("goodsmanagement:goodsmanagement:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Goodsmanagement goodsmanagement)
    {
        List<Goodsmanagement> list = goodsmanagementService.selectGoodsmanagementList(goodsmanagement);
        ExcelUtil<Goodsmanagement> util = new ExcelUtil<Goodsmanagement>(Goodsmanagement.class);
        util.exportExcel(response, list, "货物管理数据");
    }

    /**
     * 获取货物管理详细信息
     */
    @RequiresPermissions("goodsmanagement:goodsmanagement:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(goodsmanagementService.selectGoodsmanagementById(id));
    }

    /**
     * 新增货物管理
     */
    @RequiresPermissions("goodsmanagement:goodsmanagement:add")
    @PostMapping
    public AjaxResult add(@RequestBody Goodsmanagement goodsmanagement)
    {
        goodsmanagement.setStatus(1);
        goodsmanagement.setTime(new Date());
        return toAjax(goodsmanagementService.insertGoodsmanagement(goodsmanagement));
    }

    /**
     * 修改货物管理
     */
    @RequiresPermissions("goodsmanagement:goodsmanagement:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody Goodsmanagement goodsmanagement)
    {
        return toAjax(goodsmanagementService.updateGoodsmanagement(goodsmanagement));
    }

    /**
     * 删除货物管理
     */
    @RequiresPermissions("goodsmanagement:goodsmanagement:remove")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(goodsmanagementService.deleteGoodsmanagementByIds(ids));
    }
}
